//
//  ChatWindow.m
//  aorc
//
//  Created by Reza Jelveh
//  Copyright 2007
//  License: GPL
//

#import "ChatWindow.h"
#import "ChatController.h"

@implementation ChatWindow
- (void)sendEvent:(NSEvent *)theEvent
{
	NSTextField * inputTextField;
 	if(!tabView) 
		tabView = (NSTabView*)[self initialFirstResponder];
	
	
	inputTextField = [[tabView selectedTabViewItem] initialFirstResponder];
		

	if ([theEvent type] != NSKeyDown) {
		[super sendEvent:theEvent];
		return;
	}
	
	if([[self firstResponder] isKindOfClass:[NSTableView class]]){
		// See if the return key was pressed inside the tableView
		if ([[theEvent characters] isEqual:@"\r"]){
			[[ChatController sharedManager] setTellTarget];
			return;
		}
		// If tab key pressed set input to the current textInput
		else if([[theEvent characters] isEqual:@"\t"]){
			[super sendEvent:theEvent];
			return;
		}
	}
	if ([theEvent modifierFlags] & NSNumericPadKeyMask) {
		[super sendEvent:theEvent];
		return;
  }
		
	if(![[self firstResponder] respondsToSelector:@selector(isDescendantOf:)] || ![[self firstResponder] isDescendantOf:inputTextField])
		[self makeFirstResponder:inputTextField];
		
	[super sendEvent:theEvent];
}

- (void)performClose:(id)sender
{
	// don't allow the chat window to be closed ...
}

@end
